'use strict';

describe 'service ', ()->

  beforeEach(module('UCX.Cmis'))

  describe 'service ApiService getSharedFileLink', ()->
    beforeEach(()->
#      jasmine.Ajax.install()
    )
    afterEach(()->
#      jasmine.Ajax.uninstall()
    )
    it 'getSharedFileLink ', inject (ApiService,CmisService,$httpBackend,$rootScope)->

      CmisService.baseUrl = '123'
      CmisService.token = '123'
      file={}
      file.id='111111'
      file.sharedLink = 'qq.com'


      spyOn($, "ajax")
      console.log CmisService.baseUrl
#      $httpBackend.whenGET('app/dashboard/dashboard.html').respond('')
      $httpBackend.expectGET(CmisService.baseUrl+'api/share/public?access-token='+CmisService.token ).respond({
        data:{
          message:'success'
        },
        ret:0
      })
      ApiService.getSharedFileLink(file,true).then((response)->
        window.sequence = response
      )
      $httpBackend.flush()
      $rootScope.$digest()
      expect(sequence.data.message).toEqual('success')

    it 'closeSharedLink ', inject (Utils)->





  describe 'service Utils containIllegalChar', ()->
    beforeEach(()->
      #  必须绑定到 window 对象上 因为coffee 默认是 闭包 外部无法访问内部变量
      window.strWithIllegal1 = 'hello/'
      window.strWithIllegal2 = 'hello\\'
      window.strWithIllegal3 = 'hello:'
      window.strWithIllegal4 = 'hello"'
      window.strWithIllegal5 = 'hello?'
      window.strWithIllegal6 = 'hello<'
      window.strWithIllegal7 = 'hello>'
      window.strWithIllegal8 = 'hello|'
      window.strWithIllegal9 = 'hello%'
      window.strWithLegal = 'hello'
    )
    afterEach(()->
#      document.body.removeChild(document.getElementById('fixture'))
    )
    it 'strWithIllegal: containIllegalChar /, \\, :, ", *, ?, <, >, |, %', inject (Utils)->
      expect(Utils.containIllegalChar(strWithIllegal1)).toEqual(true)
      expect(Utils.containIllegalChar(strWithIllegal2)).toEqual(true)
      expect(Utils.containIllegalChar(strWithIllegal3)).toEqual(true)
      expect(Utils.containIllegalChar(strWithIllegal4)).toEqual(true)
      expect(Utils.containIllegalChar(strWithIllegal5)).toEqual(true)
      expect(Utils.containIllegalChar(strWithIllegal6)).toEqual(true)
      expect(Utils.containIllegalChar(strWithIllegal7)).toEqual(true)
      expect(Utils.containIllegalChar(strWithIllegal8)).toEqual(true)
      expect(Utils.containIllegalChar(strWithIllegal9)).toEqual(true)
    it 'strWithLegal does not containIllegalChar ', inject (Utils)->
      console.log(strWithLegal)
      expect(Utils.containIllegalChar(strWithLegal)).toEqual(false)

  describe 'service Utils getFileExt', ()->
    beforeEach(()->
#  必须绑定到 window 对象上 因为coffee 默认是 闭包 外部无法访问内部变量
      window.fileName1 = 'hello.exe'
      window.fileName2 = 'hello.Exe'
      window.fileName3 = 'hello.xl.exe'
      window.fileName4 = 'hello.dw'
      window.fileName5 = 'hello'
    )
    afterEach(()->
#      document.body.removeChild(document.getElementById('fixture'))
    )
    it 'getFileExt fileName ', inject (Utils)->
      expect(Utils.getFileExt(fileName1)).toEqual('exe')
      expect(Utils.getFileExt(fileName2)).toEqual('exe')
      expect(Utils.getFileExt(fileName3)).toEqual('exe')
      expect(Utils.getFileExt(fileName4)).toEqual('dw')
      expect(Utils.getFileExt(fileName5)).toEqual('')

  describe 'service Utils isImg', ()->
    beforeEach(()->
#  必须绑定到 window 对象上 因为coffee 默认是 闭包 外部无法访问内部变量
      window.document1 = {
        type:'image/png'
      }
      window.document2 = {
        contentStreamMimeType:'image/'
      }
      window.document3 = {
        type:'application/pdf'
      }
      window.document4 = {

      }
    )
    afterEach(()->
#      document.body.removeChild(document.getElementById('fixture'))
      window.document1 = window.document2 = window.document3 =window.document4 = ''
    )
    it 'type or contentStreamMineType ', inject (Utils)->
      expect(Utils.isImg(document1)).toEqual(true)
      expect(Utils.isImg(document2)).toEqual(true)
      expect(Utils.isImg(document3)).toEqual(false)
      expect(Utils.isImg(document4)).toEqual(false)



  describe 'service Utils isTxt', ()->
    beforeEach(()->
#  必须绑定到 window 对象上 因为coffee 默认是 闭包 外部无法访问内部变量
      window.document1 = {
        type:'text/png'
      }
      window.document2 = {
        contentStreamMimeType:'text/png'
      }
      window.document3 = {
        type:'application/pdf'
      }
      window.document4 = {

      }
    )
    afterEach(()->
#      document.body.removeChild(document.getElementById('fixture'))
      window.document1 = window.document2 = window.document3 =window.document4 = ''
    )
    it 'type or contentStreamMineType ', inject (Utils)->
      expect(Utils.isText(document1)).toEqual(true)
      expect(Utils.isText(document2)).toEqual(true)
      expect(Utils.isText(document3)).toEqual(false)
      expect(Utils.isText(document4)).toEqual(false)

  describe 'service Utils canPreview', ()->
    # init data below
    window.allowPreviewTypes = [
      'application/pdf'
      'application/msword'
      'application/vnd.ms-powerpoint'
      'application/vnd.ms-excel'
      'application/x-mswrite'
      'application/rtf'
      'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
      'application/vnd.openxmlformats-officedocument.presentationml.presentation'
      'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
      'text/plain'
      'image/bmp'
      'image/png'
      'image/gif'
      'image/jpeg'
      'image/tiff'
    ]

    beforeEach(()->

#      not support bellow
#      for key,value of window.allowPreviewTypes
#        window['document'+key]['contentStreamMimeType'] = value


      window.document0 = {
        contentStreamMimeType:window.allowPreviewTypes[0]
      }
      window.document1 = {
        contentStreamMimeType:allowPreviewTypes[1]
      }
      window.document2 = {
        contentStreamMimeType:allowPreviewTypes[2]
      }
      window.document3 = {
        contentStreamMimeType:allowPreviewTypes[3]
      }
      window.document4 = {
        contentStreamMimeType:allowPreviewTypes[4]
      }
      window.document5 = {
        contentStreamMimeType:allowPreviewTypes[5]
      }
      window.document6 = {
        contentStreamMimeType:allowPreviewTypes[6]
      }
      window.document7 = {
        contentStreamMimeType:allowPreviewTypes[7]
      }
      window.document8 = {
        contentStreamMimeType:allowPreviewTypes[8]
      }
      window.document9 = {
        contentStreamMimeType:allowPreviewTypes[9]
      }
      window.document10 = {
        contentStreamMimeType:allowPreviewTypes[10]
      }
      window.document11 = {
        contentStreamMimeType:allowPreviewTypes[11]
      }
      window.document12 = {
        contentStreamMimeType:allowPreviewTypes[12]
      }
      window.document13 = {
        contentStreamMimeType:allowPreviewTypes[13]
      }
      window.document14 = {
        contentStreamMimeType:allowPreviewTypes[14]
      }
    )
    afterEach(()->
#      document.body.removeChild(document.getElementById('fixture'))
    )
    it 'can preview '+window.allowPreviewTypes[0], inject (Utils)->
      expect(Utils.canPreview(document0)).toEqual(true)
    it 'can preview '+window.allowPreviewTypes[1], inject (Utils)->
      expect(Utils.canPreview(document1)).toEqual(true)
    it 'can preview '+window.allowPreviewTypes[2], inject (Utils)->
      expect(Utils.canPreview(document2)).toEqual(true)
    it 'can preview '+window.allowPreviewTypes[3], inject (Utils)->
      expect(Utils.canPreview(document3)).toEqual(true)
    it 'can preview '+window.allowPreviewTypes[4], inject (Utils)->
      expect(Utils.canPreview(document4)).toEqual(true)
    it 'can preview '+window.allowPreviewTypes[5], inject (Utils)->
      expect(Utils.canPreview(document5)).toEqual(true)
    it 'can preview '+window.allowPreviewTypes[6], inject (Utils)->
      expect(Utils.canPreview(document6)).toEqual(true)
    it 'can preview '+window.allowPreviewTypes[7], inject (Utils)->
      expect(Utils.canPreview(document7)).toEqual(true)
    it 'can preview '+window.allowPreviewTypes[8], inject (Utils)->
      expect(Utils.canPreview(document8)).toEqual(true)
    it 'can preview '+window.allowPreviewTypes[9], inject (Utils)->
      expect(Utils.canPreview(document9)).toEqual(true)
    it 'can preview '+window.allowPreviewTypes[10], inject (Utils)->
      expect(Utils.canPreview(document10)).toEqual(true)
    it 'can preview '+window.allowPreviewTypes[11], inject (Utils)->
      expect(Utils.canPreview(document11)).toEqual(true)
    it 'can preview '+window.allowPreviewTypes[12], inject (Utils)->
      expect(Utils.canPreview(document12)).toEqual(true)
    it 'can preview '+window.allowPreviewTypes[13], inject (Utils)->
      expect(Utils.canPreview(document13)).toEqual(true)
    it 'can preview '+window.allowPreviewTypes[14], inject (Utils)->
      expect(Utils.canPreview(document14)).toEqual(true)





